package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PackageMapper {
    void updatePackage(Setmeal setmeal);

    Page<SetmealVO> page(SetmealPageQueryDTO setmealPageQueryDTO);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into setmeal (category_id, name, price, status," +
            " description, image, create_time, update_time," +
            " create_user, update_user) values " +
            "(#{categoryId},#{name},#{price},#{status},#{description}" +
            ",#{image},#{createTime},#{updateTime},#{createUser}," +
            "#{updateUser})")
    void addPackage(Setmeal setmeal);

    @Update("update setmeal set status = #{status} where id = #{id}")
    void status(String status, Long id);

    @Select("select d.status from (select sd.dish_id from setmeal s left join setmeal_dish sd on s.id = sd.setmeal_id where s.id = #{id}) sds left join dish d on sds.dish_id = d.id")
    List<Integer> getDishStatus(Long id);

    void deletePackage(List<Integer> ids);

    List<Integer> getById(List<Integer> ids);

    void deleteSetmealDish(List<Integer> ids);

    @Select("select * from setmeal where id = #{id}")
    Setmeal getPackageById(Long id);
}
